package com.crm.sys.tab;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

import org.springframework.stereotype.Repository;
import org.springframework.web.servlet.tags.RequestContextAwareTag;

import com.crm.util.Constants;



/**
 * 安全标签
 * @author Administrator
 *
 */
@Repository
public class SecurityTag extends RequestContextAwareTag{

	/**
	 * 
	 */
	private static final long serialVersionUID = 5285172084974037403L;

    private String value; //传入的内容
    private int type=0;  //类型  0 加密   1 解密
	public void setValue(String value) {
		this.value = value;
	} 
	public void setType(int type) {
		this.type = type;
	}
 
	@Override
	protected int doStartTagInternal() throws Exception {  
        JspWriter out = this.pageContext.getOut();  
          
        try {  
        	 String  content = "";
        	  try{
        		   switch (type) {
				case 0:
					content = Constants.CONTENT.encryptString(value);
					break;
				case 1:
					content = Constants.CONTENT.decryptString(value);
					break;
				default:
					break;
				}
        		 out.print(content);  
		       	}catch(Exception e1){
		       	 out.print("");  
		       	}
           
        } catch (IOException e) {  
            //e.printStackTrace();  
        }  
          
      
        return EVAL_BODY_INCLUDE;  
    }  
 
 
    public int doAfterBody() throws JspException{  
        return SKIP_BODY;  
    }  
    public int doEndTag() throws JspException{  
        return EVAL_PAGE;  
    }  
}
